package com.czy.owner.adapter;

import android.content.Context;
import android.support.v4.content.ContextCompat;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.czy.owner.R;
import com.czy.owner.entity.CarArchiveType;

import java.util.List;

/**
 * Created by King on 2016/7/20 0020.
 */
public class ArchiveTypeAdapter extends BaseRecyclerAdapter<CarArchiveType, ArchiveTypeAdapter.ArchiveTypeViewHolder> {
    private CarArchiveType selectedArchiveType;
    private boolean isCustom;

    public boolean isCustom() {
        return isCustom;
    }

    public ArchiveTypeAdapter(Context context, List<CarArchiveType> data) {
        super(context, data);
    }

    public void setSelectedArchiveType(CarArchiveType str) {

        this.selectedArchiveType = str;
    }

    public void setCustom(boolean custom) {
        isCustom = custom;
    }

    public CarArchiveType getSelectedArchiveType() {
        return selectedArchiveType;
    }

    @Override
    public void onBindViewHolder(ArchiveTypeViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);
        holder.bindData(data.get(position));
    }

    @Override
    public ArchiveTypeViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ArchiveTypeViewHolder(layoutInflater.inflate(R.layout.item_archive_add_recycler, parent, false));
    }

    public class ArchiveTypeViewHolder extends BaseRecyclerAdapter.ViewHolder {
        private TextView tvTypeItem;

        public ArchiveTypeViewHolder(View itemView) {
            super(itemView);
            tvTypeItem = (TextView) itemView.findViewById(R.id.tv_province_code_item);
        }

        public void bindData(CarArchiveType mType) {
            if (selectedArchiveType != null && selectedArchiveType.getCarFilesCostTypeId() == mType.getCarFilesCostTypeId()) {
                tvTypeItem.setTextColor(ContextCompat.getColor(mContext, R.color.white));
                tvTypeItem.setBackground(ContextCompat.getDrawable(mContext, R.drawable.shape_archive_add_type_item_selected));
            } else {
                tvTypeItem.setTextColor(ContextCompat.getColor(mContext, R.color.mainTabFontColor));
                tvTypeItem.setBackground(ContextCompat.getDrawable(mContext, R.drawable.shape_archive_add_type_item_normal));
            }
            tvTypeItem.setText(mType.getTypeName());
        }
    }
}
